package group.igfd.manager.biz.service.impl;

import group.igfd.manager.biz.model.BuyerUser;
import group.igfd.manager.biz.dao.UsersDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import group.igfd.manager.biz.entity.UsersEntity;
import group.igfd.manager.biz.service.UsersService;


@Service("usersService")
public class UsersServiceImpl extends ServiceImpl<UsersDao, UsersEntity> implements UsersService {

    @Autowired
    private UsersDao usersDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<UsersEntity> page = this.selectPage(
                new Query<UsersEntity>(params).getPage(),
                new EntityWrapper<UsersEntity>()
        );

        return new PageUtils(page);
    }

    public String getNickName(String uid){
        EntityWrapper<UsersEntity> ew = new EntityWrapper<>();
        ew.eq("uid", uid);
        UsersEntity entity = this.selectOne(ew);
        if(null == entity){
            return "default name";
        }
        return entity.getNickname();
    }

    @Override
    public List<BuyerUser> getBuyers() {
        return usersDao.getBuyers();
    }

}
